use "$dataDir/dataset_birthoutcomes_pollution", clear

local controls "edad_madre total_consultas"
local vd "weight gweeks vlowb vpreterm"

foreach vd in `vd'{
	reghdfe  `vd' pm25_pred  `controls', abs(geoid year) vce(cluster geoid)
		estimates store `vd'_pm25_pred
		estadd local yearfe "Yes"
		estadd local locfe "Yes"	
		estadd local cluslvl "Locality"
}
local vd "weight gweeks vlowb vpreterm"
foreach vd in `vd'{
	reghdfe  `vd' l1_pm25_pred  `controls', abs(geoid year) vce(cluster geoid)
		estimates store `vd'_l1_pm25_pred
		estadd local yearfe "Yes"
		estadd local locfe "Yes"	
		estadd local cluslvl "Locality"
}
local vd "weight gweeks vlowb vpreterm"	
foreach vd in `vd'{
	reghdfe  `vd' l2_pm25_pred  `controls', abs(geoid year) vce(cluster geoid)
		
		estimates store `vd'_l2_pm25_pred
		estadd ysumm, mean
		estadd local yearfe "Yes"
		estadd local locfe "Yes"	
		estadd local cluslvl "Locality"
}




*LONG TABLE
	esttab weight_pm25_pred gweeks_pm25_pred vlowb_pm25_pred vpreterm_pm25_pred using "$mainDir/tables/TabA7_birthoutcomes_pollution.tex", replace b(%12.5fc) se keep(pm25_pred) varlabels(pm25_pred  "Pollution in w-4 weeks") label nonotes postfoot(" ") posthead(" \hline \\ [-1.8ex] & \multicolumn{4}{c}{Panel a)} \\") prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\begin{tabular}{l*{1}{cccc}}\hline \hline") nolines  starl(* 0.1 ** 0.05 *** 0.01) 
	esttab weight_l1_pm25_pred gweeks_l1_pm25_pred vlowb_l1_pm25_pred vpreterm_l1_pm25_pred using "$mainDir/tables/TabA7_birthoutcomes_pollution.tex", append b(%12.5fc) se keep(l1_pm25_pred) varlabels(l1_pm25_pred  "Pollution in w-8 weeks") label  prehead("")  nomtitle nonumbers  posthead(" \hline \\ [-1.8ex] & \multicolumn{4}{c}{Panel b)} \\") nonotes postfoot(" ")  nolines starl(* 0.1 ** 0.05 *** 0.01) 
	esttab weight_l2_pm25_pred gweeks_l2_pm25_pred vlowb_l2_pm25_pred vpreterm_l2_pm25_pred using "$mainDir/tables/TabA7_birthoutcomes_pollution.tex", append b(%12.5fc) se keep(l2_pm25_pred) varlabels(l2_pm25_pred  "Pollution in w-12 weeks") label prehead("")  nomtitle nonumbers posthead(" \hline \\ [-1.8ex] & \multicolumn{4}{c}{Panel c)} \\") nonotes  nolines starl(* 0.1 ** 0.05 *** 0.01) stats(N ymean r2 yearfe locfe  cluslvl, fmt(%12.0fc %12.3fc) label( "Observations" "Mean Dep. Variable" "R-squared" "Year FE" "Locality FE" "Cluster level")) nonotes postfoot("\hline \hline \end{tabular}}")
	

use "$dataDir/dataset_birthoutcomes_vulnerable_mothers_pollution", clear

local controls "edad_madre total_consultas"
local vd "weight gweeks vlowb vpreterm"

foreach vd in `vd'{
	reghdfe  `vd' pm25_pred  `controls', abs(geoid year) vce(cluster geoid)
		estimates store `vd'_pm25_pred_vm
		estadd ysumm, mean
		estadd local yearfe "Yes"
		estadd local locfe "Yes"	
		estadd local cluslvl "Locality"
	reghdfe  `vd' l1_pm25_pred  `controls', abs(geoid year) vce(cluster geoid)
		estimates store `vd'_l1_pm25_pred_vm
		estadd ysumm, mean
		estadd local yearfe "Yes"
		estadd local locfe "Yes"	
		estadd local cluslvl "Locality"
	reghdfe  `vd' l2_pm25_pred  `controls', abs(geoid year) vce(cluster geoid)
		estimates store `vd'_l2_pm25_pred_vm
		estadd ysumm, mean
		estadd local yearfe "Yes"
		estadd local locfe "Yes"	
		estadd local cluslvl "Locality"

}

la var pm25_pred "Pollution{sub:t}"
la var l1_pm25_pred "Pollution{sub:t-1}"
la var l2_pm25_pred "Pollution{sub:t-2}"	


*LONG TABLE
	esttab weight_pm25_pred_vm gweeks_pm25_pred_vm vlowb_pm25_pred_vm vpreterm_pm25_pred_vm using "$mainDir/tables/TabA8_birthoutcomes_pollution_vulnerable_mothers.tex", replace b(%12.5fc) se keep(pm25_pred) varlabels(pm25_pred  "Pollution in w-4 weeks") label nonotes postfoot(" ") posthead(" \hline \\ [-1.8ex] & \multicolumn{4}{c}{Panel a)} \\") prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\begin{tabular}{l*{1}{cccc}}\hline \hline") nolines starl(* 0.1 ** 0.05 *** 0.01) 
	esttab weight_l1_pm25_pred_vm gweeks_l1_pm25_pred_vm vlowb_l1_pm25_pred_vm vpreterm_l1_pm25_pred_vm using "$mainDir/tables/TabA8_birthoutcomes_pollution_vulnerable_mothers.tex", append b(%12.5fc) se keep(l1_pm25_pred) varlabels(l1_pm25_pred  "Pollution in w-8 weeks") label  prehead("")  nomtitle nonumbers  posthead(" \hline \\ [-1.8ex] & \multicolumn{4}{c}{Panel b)} \\") nonotes postfoot(" ")  nolines starl(* 0.1 ** 0.05 *** 0.01) 
	esttab weight_l2_pm25_pred_vm gweeks_l2_pm25_pred_vm vlowb_l2_pm25_pred_vm vpreterm_l2_pm25_pred_vm using "$mainDir/tables/TabA8_birthoutcomes_pollution_vulnerable_mothers.tex", append b(%12.5fc) se keep(l2_pm25_pred) varlabels(l2_pm25_pred  "Pollution in w-12 weeks") label prehead("")  nomtitle nonumbers posthead(" \hline \\ [-1.8ex] & \multicolumn{4}{c}{Panel c)} \\") nonotes  nolines starl(* 0.1 ** 0.05 *** 0.01) stats(N ymean r2 yearfe locfe  cluslvl, fmt(%12.0fc %12.3fc) label( "Observations" "Mean Dep. Variable" "R-squared" "Year FE" "Locality FE" "Cluster level")) nonotes postfoot("\hline \hline \end{tabular}}")
	
